﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfAGVSystem.Common;

namespace WpfAGVSystem.DBModel
{
    public class TaskTypeMgrClass
    {
        public TaskType_Entity TaskType_EF { get; set; }


        public List<object> ForntActionItems
        {
            get
            {
                string[] lists = StringProcess.Split(TaskType_EF.ForntAction);
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        var a=  ComBoxList.AGVActionEnumList.FirstOrDefault(x=>x.Val== result);
                        items.Add(a);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.ForntAction = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{StringProcess.Delimiter}");
                    }
                }
                TaskType_EF.ForntAction = stringBuilder.ToString();
            }
        }

        public List<object> TargetActionItems
        {
            get
            {
                string[] lists = StringProcess.Split(TaskType_EF.TargetAction);
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        var a = ComBoxList.AGVActionEnumList.FirstOrDefault(x => x.Val == result);
                        items.Add(a);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.TargetAction = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{StringProcess.Delimiter}");
                    }
                }
                TaskType_EF.TargetAction = stringBuilder.ToString();
            }
        }

        public List<object> RearActionItems
        {
            get
            {
                string[] lists = StringProcess.Split(TaskType_EF.RearAction);
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        var a = ComBoxList.AGVActionEnumList.FirstOrDefault(x => x.Val == result);
                        items.Add(a);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.RearAction = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{StringProcess.Delimiter}");
                    }
                }
                TaskType_EF.RearAction = stringBuilder.ToString();
            }
        }

        public List<object> TaskPreTaskItems
        {
            get 
            {
                string[] lists = StringProcess.Split(TaskType_EF.TaskPreTask);
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        var a = ComBoxList.AGVActionEnumList.FirstOrDefault(x => x.Val == result);
                        items.Add(a);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.TaskPreTask = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{StringProcess.Delimiter}");
                    }
                }
                TaskType_EF.TaskPreTask = stringBuilder.ToString();
            }
        }

        public List<object> TaskStartExcuteItems
        {
            get
            {
                string[] lists = StringProcess.Split(TaskType_EF.TaskStartExcute);
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        var a = ComBoxList.AGVActionEnumList.FirstOrDefault(x => x.Val == result);
                        items.Add(a);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.TaskStartExcute = null; return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{StringProcess.Delimiter}");
                    }
                }
                TaskType_EF.TaskStartExcute = stringBuilder.ToString();

            }
        }

        public List<object> TaskStartFinishItems
        {
            get
            {
                string[] lists = StringProcess.Split(TaskType_EF.TaskStartFinish);
                List<object> items = new List<object>();
                foreach (var list in lists)
                {
                    if (int.TryParse(list, out int result))
                    {
                        var a = ComBoxList.AGVActionEnumList.FirstOrDefault(x => x.Val == result);
                        items.Add(a);
                    }
                }
                return items;
            }
            set
            {
                if (value == null) { TaskType_EF.TaskStartFinish = null;return; }
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var item in value)
                {
                    if (int.TryParse($"{item}", out int result))
                    {
                        stringBuilder.Append($"{result}{StringProcess.Delimiter}");
                    }
                }
                TaskType_EF.TaskStartFinish = stringBuilder.ToString();
            }
        }
    }
}
